package edu.pku.sei.transformation.editor.controller.commands.node;

import org.eclipse.gef.commands.Command;

import edu.pku.sei.modeler.model.core.MetaPackage;
import edu.pku.sei.transformation.editor.model.constraint.Constraint;

public class ModelTypeConstraintCreateCommand extends Command {
	private MetaPackage ownedPkg;
	private Constraint constraint;

	public ModelTypeConstraintCreateCommand(MetaPackage pkg,
			Constraint constraint) {
		this.constraint = constraint;
		this.ownedPkg = pkg;
	}

	@Override
	public boolean canExecute() {
		if (constraint != null && ownedPkg != null)
			return true;
		else
			return false;
	}

	@Override
	public void execute() {
		ownedPkg.getOtherElements().add(0, constraint);
	}

	@Override
	public void undo() {
		ownedPkg.getOtherElements().remove(constraint);
	}

}
